#ifndef _X_THREAD_H
#define _X_THREAD_H
#include "xDef.h"
#include <pthread.h>
#include <vector>
#include <sys/epoll.h>
#include <unistd.h>
namespace xNet
{
    NET_ENGINE_CORE_API enum THREAD_STATE
    {
        THREAD_STATE_NOT_INIT = 0,
        THREAD_STATE_INITED,
        THREAD_STATE_RUNNING,
        THREAD_STATE_IDLE,
        THREAD_STATE_EXIT
    };

    NET_ENGINE_CORE_API class xThread
    {
        public:
            xThread();
            virtual ~xThread();
        public:
            static void* ThreadFunc(void* arg);
        public:
            virtual bool Run()=0;
            virtual void Finish();
            void Join();
            void Start();
        private:
            MACRO_PROPERTY_DEF(bool,m_bStart,Start)
            MACRO_PROPERTY_DEF(bool,m_bTermnation,Termnation)
            MACRO_PROPERTY_DEF(bool,m_bDetach,Detach)
            MACRO_PROPERTY_DEF(bool,m_bJoin,Join)
            MACRO_PROPERTY_DEF(pthread_t,m_pthreadId,PthreadId)
            MACRO_PROPERTY_DEF(THREAD_STATE,m_state,State)
    };

    NET_ENGINE_CORE_API class xThreadContainer
    {
        public:
            xThreadContainer(uint32 defaultSize = 1);
        public:
            void AddThread(xThread* th);
            xThread* GetThread(uint32 dwIndex);
            void Finish();
        private:
            typedef std::vector<xThread*> ThreadContainer;
            ThreadContainer m_threads;
    };
};

#endif